// import { intersection } from 'lodash-es'

// const { t } = useI18n()
// const { wsCache } = useCache()

// 全部权限
// const all_permission = ['*.*.*']

const hasPermission = (value) => {
  console.log(value)
  // const permissions = wsCache.get(appStore.getUserInfo).permissions
  // if (!value) {
  //   throw new Error("没有权限")
  // }
  // if (Array.isArray(value)) {
  //   return permissions?.includes(value)
  // }
  // if (all_permission[0] === permissions[0]) {
  //   return true
  // }
  // return (intersection(value, permissions)).length > 0
}

function hasPermi(el, binding) {
  const value = binding.value
  const flag = hasPermission(value)
  if (!flag) {
    el.parentNode?.removeChild(el)
  }
}
const permiDirective = {
  mounted: (el, binding) => {
    hasPermi(el, binding)
  }
}

export const setupPermissionDirective = (app) => {
  app.directive('hasPermi', permiDirective)
}

export default permiDirective
